import serial
import serial.tools.list_ports

def scan_serial_ports():
    # 获取所有可用串口
    ports = serial.tools.list_ports.comports()
    available_ports = []
    
    # 遍历所有串口并添加到列表中
    for port, desc, hwid in sorted(ports):
        available_ports.append((port, desc))
        print(f"发现串口: {port} - {desc}")
    
    return available_ports

if __name__ == "__main__":
    scan_serial_ports()
